package com.taldh.algorithm.treenode;

import com.taldh.algorithm.base.TreeNode;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Stack;

public class KthLargest {

    public int kthLargest(TreeNode root, int k) {
        ArrayList<Integer> result = new ArrayList<>();
        Stack<TreeNode> stack = new Stack<>();
        TreeNode treeNode = root;
        while (!stack.isEmpty()) {
            if (treeNode == null) {
                treeNode = stack.pop();
            }

            if (treeNode.left != null) {
                stack.push(treeNode);
                treeNode = treeNode.left;
            } else {
                result.add(treeNode.val);
            }
        }
        return result.get(result.size() - k);
    }

}